import req from '@/request.js'
import {Promise} from 'q'
const baseUrl = window.context.baseUrl

export default {
  //排课规则
  getRuleList(param) {
    return new Promise((resolve, reject) => {
      req.post(baseUrl + '/core/icsBPkgz/v1/listJson', param).then(
        response => {
          resolve(response.data)
        },
        error => {
          reject(error)
        }
      )
    })
  },
  removeRuleData(ids) {
    return new Promise((resolve, reject) => {
      req.remove(baseUrl + '/core/icsBPkgz/v1/remove?ids=' + ids).then(
        resp => {
          resolve(resp.data)
        },
        error => {
          reject(error)
        }
      )
    })
  },
  getRuleData(id) {
    return new Promise((resolve, reject) => {
      req.get(baseUrl + `/core/icsBPkgz/v1/getDetail?id=${id}`).then(
        resp => {
          resolve(resp.data)
        },
        error => {
          reject(error)
        }
      )
    })
  },
  saveRuleData(data) {
    return new Promise((resolve, reject) => {
      req.post(baseUrl + '/core/icsBPkgz/v1/save', data).then(
        resp => {
          resolve(resp.data)
        },
        error => {
          reject(error)
        }
      )
    })
  },
  changeRuleStatus(id, status) {
    return new Promise((resolve, reject) => {
      req
        .get(baseUrl + `/core/icsBPkgz/v1/changeStatus?id=${id}&status=${status}`)
        .then(
          resp => {
            resolve(resp.data)
          },
          error => {
            reject(error)
          }
        )
    })
  },
  getRuleGroupList() {
    return new Promise((resolve, reject) => {
      req.get(baseUrl + `/core/icsBPkgz/v1/getGroupList`).then(
        resp => {
          resolve(resp.data)
        },
        error => {
          reject(error)
        }
      )
    })
  },
  //排课属性
  getPropertyList(param) {
    return new Promise((resolve, reject) => {
      req.post(baseUrl + '/core/icsBPksx/v1/listJson', param).then(
        response => {
          resolve(response.data)
        },
        error => {
          reject(error)
        }
      )
    })
  },
  initDefaultProperty() {
    return new Promise((resolve, reject) => {
      req.get(baseUrl + `/core/icsBPksx/v1/initDefaultProperty`).then(
        resp => {
          resolve(resp.data)
        },
        error => {
          reject(error)
        }
      )
    })
  },
  removePropertyData(ids) {
    return new Promise((resolve, reject) => {
      req.remove(baseUrl + '/core/icsBPksx/v1/remove?ids=' + ids).then(resp => {
        resolve(resp.data)
      }),
        error => {
          reject(error)
        }
    })
  },
  getPropertyData(id) {
    return new Promise((resolve, reject) => {
      req.get(baseUrl + `/core/icsBPksx/v1/getDetail?id=${id}`).then(
        resp => {
          resolve(resp.data)
        },
        error => {
          reject(error)
        }
      )
    })
  },
  savePropertyData(data) {
    return new Promise((resolve, reject) => {
      req.post(baseUrl + '/core/icsBPksx/v1/save', data).then(
        resp => {
          resolve(resp.data)
        },
        error => {
          reject(error)
        }
      )
    })
  },
  getPropertyGroupList() {
    return new Promise((resolve, reject) => {
      req.get(baseUrl + `/core/icsBPksx/v1/getGroupList`).then(
        resp => {
          resolve(resp.data)
        },
        error => {
          reject(error)
        }
      )
    })
  },
  //排课记录
  getRecoredList(param) {
    return new Promise((resolve, reject) => {
      req.post(baseUrl + '/core/icsBPkjl/v1/query', param).then(
        response => {
          resolve(response.data)
        },
        error => {
          reject(error)
        }
      )
    })
  },
  removeRecordData(ids) {
    return new Promise((resolve, reject) => {
      req.remove(baseUrl + '/core/icsBPkjl/v1/remove?ids=' + ids).then(resp => {
        resolve(resp.data)
      }),
        error => {
          reject(error)
        }
    })
  },
  getRecordData(id) {
    return new Promise((resolve, reject) => {
      req.get(baseUrl + `/core/icsBPkjl/v1/getDetail?id=${id}`).then(
        resp => {
          resolve(resp.data)
        },
        error => {
          reject(error)
        }
      )
    })
  },
  saveRecordData(data) {
    return new Promise((resolve, reject) => {
      req.post(baseUrl + '/core/icsBPkjl/v1/save', data).then(
        resp => {
          resolve(resp.data)
        },
        error => {
          reject(error)
        }
      )
    })
  },
  // 获取当前学期
  getCurrentSemester() {
    return new Promise((resolve, reject) => {
      req.get(`${ics}/data/icsBXqjbsj/v1/getCurrent`).then(
        resp => {
          resolve(resp.data)
        },
        error => {
          reject(error)
        }
      )
    })
  },
  // 获取排课属性 表单控件
  getFormFieldList() {
    return new Promise((resolve, reject) => {
      req.get(`${ics}/core/icsBPksx/v1/getList`).then(
        resp => {
          resolve(resp.data)
        },
        error => {
          reject(error)
        }
      )
    })
  },
  // 保存排课数据
  saveSemesterData(data) {
    return new Promise((resolve, reject) => {
      req.post(`${ics}/core/icsBPkjl/v1/save`, data).then(
        resp => {
          resolve(resp.data)
        },
        error => {
          reject(error)
        }
      )
    })
  },
  // 获取排课数据详情
  getSemesterDetail(id) {
    return new Promise((resolve, reject) => {
      req.get(`${ics}/core/icsBPkjl/v1/getDetail?id=${id}`).then(
        resp => {
          resolve(resp.data)
        },
        error => {
          reject(error)
        }
      )
    })
  },
  // 获取教室列表
  getClassRoomList(data) {
    return new Promise((resolve, reject) => {
      req
        .post(
          `${ics}/core/icsBPkjlcs/v1/classroomList?recordId=${data.recordId}&isRecord=${data.isRecord}`,
          data
        )
        .then(
          resp => {
            resolve(resp.data)
          },
          error => {
            reject(error)
          }
        )
    })
  },
  // 获取任务列表
  getTaskBookList(data,paramType) {
    let url = `${ics}/core/icsBPkjlcs/v1/taskBookList?recordId=${data.recordId}&isRecord=${data.isRecord}`;
    if(paramType){
      //  paramType == "unUseTaskBook" 查看未排课的任务书
      url = `${ics}/core/icsBPkjlcs/v1/getTaskBookList?recordId=${data.recordId}&isRecord=${data.isRecord}&paramType=${paramType}`;
    }
    return new Promise((resolve, reject) => {
      req
        .post(
          url,
          data
        )
        .then(
          resp => {
            resolve(resp.data)
          },
          error => {
            reject(error)
          }
        )
    })
  },
  // 导出
  exportTaskBookList(data,paramType) {
    let url = `${ics}/core/icsBPkjlcs/v1/exportTaskBookList?recordId=${data.recordId}&isRecord=${data.isRecord}&paramType=${paramType}`;
    return new Promise((resolve, reject) => {
      req
          .post(
              url,
              data,
              null,
             'arraybuffer'
          )
          .then(
              resp => {
                resolve(resp.data)
              },
              error => {
                reject(error)
              }
          )
    })
  },
  // 保存教室列表
  saveClassRoomList(data) {
    return new Promise((resolve, reject) => {
      req.post(`${ics}/core/icsBPkjlcs/v1/saveList`, data).then(
        resp => {
          resolve(resp.data)
        },
        error => {
          reject(error)
        }
      )
    })
  },
  // 删除教室 任务书
  removeClassRoomList(data) {
    return new Promise((resolve, reject) => {
      req
        .remove(
          `${ics}/core/icsBPkjlcs/v1/removeParamType?recordId=${data.recordId}&paramType=${data.paramType}&ids=${data.ids}`
        )
        .then(
          resp => {
            resolve(resp.data)
          },
          error => {
            reject(error)
          }
        )
    })
  },
  bindAicDataByCampus(recordId,campusList,paramType){
    return new Promise((resolve, reject) => {
      req.post(`${ics}/core/icsBPkjlcs/v1/bindAicDataByCampus?recordId=${recordId}&paramType=${paramType}`,campusList.split(",")).then(
          resp => {
            resolve(resp.data)
          },
          error => {
            reject(error)
          }
      )
    })
  },
  // 删除排课记录
  removeLessonData(ids) {
    return new Promise((resolve, reject) => {
      req.remove(baseUrl + '/core/icsBPkjl/v1/remove?ids=' + ids).then(
        resp => {
          resolve(resp.data)
        },
        error => {
          reject(error)
        }
      )
    })
  },
  // 开始排课
  startLesson(id) {
    return new Promise((resolve, reject) => {
      req
        .post(`${ics}/gapcurriculum/v1/autoArrangingCurriculum?pkjlId=${id}`)
        .then(
          resp => {
            resolve(resp.data)
          },
          error => {
            reject(error)
          }
        )
    })
  },
  // 排课预览
  previewLesson(data, recordId, type = '2') {
    let url = `${ics}/core/icsBPkjlcs/v1/previewWeekCurriculum?recordId=${recordId}&type=${type}`;
    if(type === '1'){
      url = `${ics}/core/icsBPkjlcs/v1/previewWeekCurriculum1?recordId=${recordId}&type=${type}`;
    }
    return new Promise((resolve, reject) => {
      req
        .post(
          url,
          data
        )
        .then(
          resp => {
            resolve(resp.data)
          },
          error => {
            reject(error)
          }
        )
    })
  },
  // 导出
  exportPreviewWeekCurriculum(data, recordId, type = 'comfortCurriculumWeek') {
    return new Promise((resolve, reject) => {
      req
        .post(
          `${ics}/core/icsBPkjlcs/v1/exportPreviewWeekCurriculum?recordId=${recordId}&type=${type}`,
          data,
          null,
          'arraybuffer'
        )
        .then(
          resp => {
            resolve(resp.data)
          },
          error => {
            reject(error)
          }
        )
    })
  },
  // 课表写入
  writeLesson(recordId, type = 'comfortCurriculumWeek') {
    return new Promise((resolve, reject) => {
      req
        .post(
          `${ics}/core/icsBPkjlcs/v1/writeCurriculum?recordId=${recordId}&type=${type}`
        )
        .then(
          resp => {
            resolve(resp.data)
          },
          error => {
            reject(error)
          }
        )
    })
  },
  // 放弃课表写入
  abandonWrite(recordId) {
    return new Promise((resolve, reject) => {
      req
        .post(
          `${ics}/core/icsBPkjlcs/v1/abandonCurriculum?recordId=${recordId}`
        )
        .then(
          resp => {
            resolve(resp.data)
          },
          error => {
            reject(error)
          }
        )
    })
  },
  // 数据字典
  getDicListByKeys(groupKeys) {
    return new Promise((resolve, reject) => {
      req.get(`${ics}/core/icsBPkjl/v1/getDic?groupKeys=${groupKeys}`).then(
        resp => {
          resolve(resp.data)
        },
        error => {
          reject(error)
        }
      )
    })
  },
  // 查看异常日志
  getErrorLog(recordId) {
    return new Promise((resolve, reject) => {
      req
        .get(
          `${ics}/core/icsBPkjlcs/v1/viewingExceptionInfo?recordId=${recordId}`
        )
        .then(
          resp => {
            resolve(resp.data)
          },
          error => {
            reject(error)
          }
        )
    })
  }
}
